package com.util;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.filechooser.FileFilter;

public class FileTest extends JFileChooser {

	public FileTest(JPanel panel) {

		

	setCurrentDirectory(new File("."));
	setAcceptAllFileFilterUsed(false);

		final String[][] fileENames = { { ".jpg", "图片格式(*.jpg)" },
										{ ".png", "图片格式(*.png)" },
										{ ".gif", "图片格式(*.gif)" },
										{ ".JPG", "图片格式(*.JPG)" },
										{ ".PNG", "图片格式(*.PNG)" },
										{ ".GIF", "图片格式(*.GIF)" }
										
									  };
		
		addChoosableFileFilter(new FileFilter() {

			public boolean accept(File file) {

				return true;
			}

			public String getDescription() {

				return "图片全部格式('*.jpg','*.JPG','*.png','*.PNG','*.gif','*.GIF')";
			}
		});
		
		for (final String[] fileEName : fileENames) {
			
			setFileFilter(new javax.swing.filechooser.FileFilter() {
	
				public boolean accept(File file) { 
	
					if (file.getName().endsWith(fileEName[0]) || file.isDirectory()) {
	
						return true;
					}
	
					return false;
				}
	
				public String getDescription() {
	
					return fileEName[1];
				}
	
			});
		}
		
	showDialog(panel, null);
	}
}